﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EzyGoEzySystem.Models;
using EzyGoEzySystem.Services;

namespace EzyGoEzySystem.Controllers
{
    public class ProfileController : Controller
    {
        //
        // GET: /Profile/
        public ActionResult Index()
        {
            ProfileModel profileModel = DataAccess.GetCorrespondingAccount(Session["Account"] as Account);
            return View(profileModel);
        }

        //
        // POST: /Profile/
        [HttpPost]
        public ActionResult Index(ProfileModel profileModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var account = Session["Account"] as Account;
                    var accountID = account.ID;
                    var newAccount = DataAccess.UpdateAccountDetails(accountID, profileModel);
                    Session["Account"] = newAccount;
                    return RedirectToAction("Index", "Home");
                }
            }
            catch
            {
                return View(profileModel);
            }

            return View(profileModel);
        }
    }
}
